// components/pcenter/pcenter.ts
import common from "../../common/index";
const app = getApp()
Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    userInfo: {}
  },

  lifetimes: {
    attached() {
      this.setData({
        userInfo: common.getAppUserInfo()
      })
    },
  },
  pageLifetimes: {
    show() {
      this.setData({
        userInfo: common.getAppUserInfo()
      })
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    closePage() {
      this.triggerEvent('close')
    },
    handleGotoLogin() {
      wx.reLaunch({
        url: '/pages/login/login?single=true'
      })
    },
    handleGotoMyArchivePage() {
      if (!common.getAppUserInfo().uid) {
        wx.showToast({
          title: '请先登录',
          icon: 'none',
        })
      } else {
        wx.navigateTo({
          url: '/pages/my-archive/my-archive'
        })
      }
    },
    handleGotoVipCenterPage() {
      if (!common.getAppUserInfo().uid) {
        wx.showToast({
          title: '请先登录',
          icon: 'none',
        })
      } else {
        wx.navigateTo({
          url: '/pages/vip-center/vip-center'
        })
      }
    },
    handleGotoVipBuyPage() {
      if (!common.getAppUserInfo().uid) {
        wx.showToast({
          title: '请先登录',
          icon: 'none',
        })
      } else {
        wx.navigateTo({
          url: '/pages/vip-buy/vip-buy'
        })
      }
    },
    handleGotoVipSharePage() {
        if (!common.getAppUserInfo().uid) {
          wx.showToast({
            title: '请先登录',
            icon: 'none',
          })
        } else {
          wx.navigateTo({
            url: '/pages/vip-share/vip-share'
          })
        }
      },
    handleLogout() {
      common.removeLocalUid()
      common.removeLocalToken()
      common.setAppUserInfo({}, app.globalData)
      common.setAppVipInfo({
        levelDesc: '',
        levelName: '',
        status: 0,
        endTime: '',
      }, app.globalData)
      wx.reLaunch({
        url: '/pages/index/index',
      })
    },
    handleCopyWebLink() {
      const webUrl = 'www.aispire.info'
      wx.setClipboardData({
        data: webUrl,
        success: () => {
          wx.showToast({
            title: '链接已复制！',
            icon: 'success',
            duration: 2000
          })
        },
        fail: () => {
          wx.showToast({
            title: '复制失败',
            icon: 'error',
            duration: 2000
          })
        }
      })
    },
  }
})